package com.diors.game.example.server.xmldata;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.diors.game.engine.arpg.scene.model.SceneModel;

/**
 * 场景数据加载Data
 * @author	darren.ouyang <ouyang.darren@gmail.com>
 * @date	2013-10-22
 * @version 1.0
 * @copyright Copyright (c) 2013, darren.ouyang
 */
@XmlRootElement(name = "scenes")
@XmlAccessorType(XmlAccessType.FIELD)
public class SceneData 
{
	
	@XmlElement(name = "scene")
	private List<SceneModel> list;

	private Map<Integer, SceneModel> map = new HashMap<Integer, SceneModel>();
	
	/**
	 * 加载xml后监听进入
	 * @param u
	 * @param parent
	 * @create	2013-9-16	darren.ouyang
	 */
	void afterUnmarshal(Unmarshaller u, Object parent)
	{
		map.clear();
		for(SceneModel model : list)
		{
			int sceneBaseID = model.getId();
			
			model.setBornModelList(XmlDataManager.NPC_BORN_DATA.getSceneBorns(sceneBaseID));
			model.setLineModel(XmlDataManager.SCENE_LINE_DATA.getModel(sceneBaseID));
			map.put(model.getId(), model);
		}
			
		list = null;
		XmlDataManager.log.info("loading SceneData size:" + map.size());
	}
	
	public Map<Integer, SceneModel> getMap ()
	{
		return map;
	}
	
	public SceneModel getModel (int id)	
	{
		return map.get(id);
	}
	
}
